from collections import namedtuple
import time

class Item:
	def __init__(self, id = "", text = None, highlight = False, action = None):
		self.id = id
		self.highlight = highlight
		if text is None:
			self.text = [id]
		elif isinstance(text, str):
			self.text = [text]
		else:
			self.text = text
		if not action:
			action = id
		if isinstance(action, str):
			action = Action(action)
		self.action = action

class Action:
	def __init__(self, url, target = "body", javascript = False):
		if not javascript:
			self.js = 'update("{}", "{}");'.format(target, url)
		else:
			self.js = url

	def __repr__(self):
		return self.js

def format_time(seconds):
	if isinstance(seconds, str):
		seconds = int(seconds)
	return time.asctime(time.localtime(seconds))

def format_duration(seconds):
	if isinstance(seconds, str):
		seconds = int(seconds)
	hours = seconds // 60
	minutes = (seconds % 60) // 60
	return "{}h {}m".format(hours, minutes)
